//
//  PopUpDemo.swift
//  YoruNeko
//
//  Created by Apple on 2021/6/21.
//

import SwiftUI

struct PopUpDemo: View {
    @State var text1:String = "a"
    @State var tempText1:String = ""
    @State var text2:String = "b"
    @State var tempText2:String = ""
    @State var isEditing:Bool = false
    private func onCommit(actionType:Bool){
        if actionType {
            self.text1 = self.tempText1
            self.text2 = self.tempText2
        }
        self.isEditing = false
    }
    var body: some View {
        
        ZStack{
            VStack{
                HStack{
                    Text(text1).padding()
                    Text(text2).padding()
                    Spacer()
                    Button(action:{
                        self.tempText1 = self.text1
                        self.tempText2 = self.text2
                        self.isEditing = true
                    }){
                        Text("改变Text")
                    }
                    .padding()
                }
                List{
                  ForEach(0..<100){ i in
                    Text("1111111111111:\(i)")
                  }
                }
            }
            if isEditing {
                PopUp(title: "编辑书签",onCommit:onCommit,content: {
                    Group{
                        Text("damn")
                        TextField("siteName", text: $tempText1)
                            .textFieldStyle(RoundedBorderTextFieldStyle())
                            .padding(.horizontal)
                            .disableAutocorrection(true)
                            .autocapitalization(.none)

                        TextField("url", text: $tempText2)
                            .textFieldStyle(RoundedBorderTextFieldStyle())
                            .padding(.horizontal)
                            .disableAutocorrection(true)
                            .autocapitalization(.none)
                    }
                })
                }
        }
    }
}

struct PopUpDemo_Previews: PreviewProvider {
    static var previews: some View {
        PopUpDemo()
    }
}
